package com.redwine.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Display;
import android.view.WindowManager;

import com.lidroid.xutils.ViewUtils;
import com.redwine.app.utils.ActivitySplitAnimationUtil;
import com.redwine.app.utils.Global;
import com.redwine.app.utils.Settings;
import com.umeng.analytics.MobclickAgent;

public class WelcomeActivity extends Activity {

    private Handler hanglerIntent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);
        MobclickAgent.setDebugMode(true);
        ViewUtils.inject(this);
        hanglerIntent = new Handler();
        Display mDisplay = getWindowManager().getDefaultDisplay();
        Global.screen_w = mDisplay.getWidth();
        Global.screen_h = mDisplay.getHeight();
        hanglerIntent.postDelayed(runnableIntent, 1000);
    }


    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("SplashScreen");
        MobclickAgent.onResume(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("SplashScreen");
        MobclickAgent.onPause(this);
    }


    private Runnable runnableIntent = new Runnable() {
        @Override
        public void run() {
            intent();
        }
    };


    public void intent() {
        Intent intent;
        if (Settings.isLoggedIn()) {
            intent = new Intent(WelcomeActivity.this, MainActivity.class);
        } else {
            intent = new Intent(WelcomeActivity.this, LoginActivity.class);
        }
        ActivitySplitAnimationUtil.startActivity(WelcomeActivity.this, intent);
        this.finish();
    }

}

